//package com.dudy.common.config;
//
//import com.dudy.common.util.OkHttpUtils;
//import okhttp3.ConnectionPool;
//import okhttp3.OkHttpClient;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.stereotype.Component;
//import org.springframework.validation.annotation.Validated;
//
//import javax.validation.constraints.NotNull;
//import java.util.concurrent.TimeUnit;
//
///**
// * @program: nacos_test
// * @author: dudy
// * @create: 2020-12-21 17:48
// * @description:
// **/
//@Configuration
//public class OkHttpConfiguration {
//
//    @Bean
//    public OkHttpClient okHttpClient() {
//        OkHttpConfig okHttpConfig = new OkHttpConfig();
//        OkHttpClient client = new OkHttpClient.Builder()
//                .retryOnConnectionFailure(false)
//                .connectionPool(pool())
//                .connectTimeout(okHttpConfig.getConnectTimeoutMs(), TimeUnit.MILLISECONDS)
//                .readTimeout(okHttpConfig.getReadTimeoutMs(), TimeUnit.MILLISECONDS)
//                .writeTimeout(okHttpConfig.getWriteTimeoutMs(), TimeUnit.MILLISECONDS)
//                .build();
//
//        OkHttpUtils.setOkHttpClient(client);
//        return client;
//    }
//
//    @Bean
//    public ConnectionPool pool() {
//        OkHttpConfig okHttpConfig = new OkHttpConfig();
//        return new ConnectionPool(okHttpConfig.getMaxIdle(), okHttpConfig.getKeepAliveDurationSec(), TimeUnit.SECONDS);
//    }
//
//    @Component
//    @ConfigurationProperties(prefix = "okhttp")
//    @Validated
//    static class OkHttpConfig {
//        @NotNull
//        private Long connectTimeoutMs;
//        @NotNull
//        private Long readTimeoutMs;
//        @NotNull
//        private Long writeTimeoutMs;
//        @NotNull
//        private Integer maxIdle;
//        @NotNull
//        private Long keepAliveDurationSec;
//
//        public Long getConnectTimeoutMs() {
//            return connectTimeoutMs;
//        }
//
//        public OkHttpConfig setConnectTimeoutMs(Long connectTimeoutMs) {
//            this.connectTimeoutMs = connectTimeoutMs;
//            return this;
//        }
//
//        public Long getReadTimeoutMs() {
//            return readTimeoutMs;
//        }
//
//        public OkHttpConfig setReadTimeoutMs(Long readTimeoutMs) {
//            this.readTimeoutMs = readTimeoutMs;
//            return this;
//        }
//
//        public Long getWriteTimeoutMs() {
//            return writeTimeoutMs;
//        }
//
//        public OkHttpConfig setWriteTimeoutMs(Long writeTimeoutMs) {
//            this.writeTimeoutMs = writeTimeoutMs;
//            return this;
//        }
//
//        public Integer getMaxIdle() {
//            return maxIdle;
//        }
//
//        public OkHttpConfig setMaxIdle(Integer maxIdle) {
//            this.maxIdle = maxIdle;
//            return this;
//        }
//
//        public Long getKeepAliveDurationSec() {
//            return keepAliveDurationSec;
//        }
//
//        public OkHttpConfig setKeepAliveDurationSec(Long keepAliveDurationSec) {
//            this.keepAliveDurationSec = keepAliveDurationSec;
//            return this;
//        }
//    }
//
//}
